package com.yd.app.mapper;

import com.yd.app.mapper.provider.AgreementProvider;
import com.yd.domain.business.Agreement;
import com.yd.domain.sys.Agent;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * Created by zg on 2018/3/9.
 */
@Repository
public interface AgentMapper {

    /**
     * 查询列表
     * @return
     */
    @Select("select * from sys_agent order by sort")
    List<Agent> getAgentList();

    /**
     * 删除代理商信息
     * @param agentId
     */
    @Select("delete from sys_agent where id=#{agentId} ")
    void deleteAgentById(@Param("agentId") String agentId);

    /**
     * 添加代理商
     * @param agent
     */
    @Select("insert into sys_agent (id,agentCompany,iconUrl,sort) values (#{agent.id},#{agent.agentCompany},#{agent.iconUrl},#{agent.sort})   ")
    void addAgent(@Param("agent") Agent agent);
    /**
     * 修改代理商
     * @param agent
     */
    @Update("update sys_agent set agentCompany=#{a.agentCompany},iconUrl=#{a.iconUrl},sort=#{a.sort} where id=#{a.id} ")
    void updateAgent(@Param("a") Agent agent);
    /**
     * 获取登录用户所注册的代理
     * @param userId
     * @return
     */
    @Select("select a.* from sys_user u left join sys_agent a on u.agentId=a.id where u.id=#{userId}  ")
    Agent getAgentByUser(@Param("userId") String userId);
}
